Module Module1
    'These variables are here so that all the sub's can get access
    'sText contains the first response
    Public sText As String
    'strTextFile is used to write to the therapy log file
    Public strTextFile As System.IO.StreamWriter
    Sub Main()
        'This sets up the file writing. From now on strTextFile can be used to write to the therapy log file
        strTextFile = New System.IO.StreamWriter("therapylog.txt", True)

        'Intro line and a few spaces before the main program begins
        Console.WriteLine("Eliza Project Assignment")
        Console.Write(vbCrLf & vbCrLf)

        'Writes the date and time to the log file so that you can distinguish between entrys
        strTextFile.WriteLine(Today & " " & TimeOfDay)

        'Primary non-commital question to distinguish routes of questioning
        Console.WriteLine("Tell me your problems")
        'also logged to file with the prefix "EL:" indicating that it is the program talking
        strTextFile.WriteLine("EL:" & "Tell me your problems")

        'Get the response
        sText = Console.ReadLine()
        'log the patients response to file. Again prefied this time with "PT:" to indicate patient
        strTextFile.WriteLine("PT:" & sText)

        'large if else block to choose the appropriate questioning route.
        'Routes are detected by the presence of keywords.
        If (sText.ToLower().Contains("afraid")) Then
            FearQuestions()
        ElseIf (sText.ToLower().Contains("angry")) Then
            AngerQuestions()
        ElseIf (sText.ToLower().Contains("depressed")) Then
            DepressionQuestions()
        ElseIf (sText.ToLower().Contains("doubtful")) Then
            DoubtfulQuestions()
        Else
            'Nono commital message incase the user enters a messange that the program cant handle.
            Console.WriteLine("Im sorry but i can't help you with that problem")
            strTextFile.WriteLine("EL:Im sorry but i can't help you with that problem")
        End If

        'write some empty lines to the log to leave a gap between entrys
        strTextFile.Write(vbCrLf & vbCrLf)
        'Close the file properly
        strTextFile.Close()

        'Message at the end of the program with a readkey to hold the program open until a key is pressed
        Console.WriteLine("Press Any Key To Exit...")
        Console.ReadKey()
    End Sub

    Sub FearQuestions()
        'Fear text and input buffers
        Dim sFear, sFearReason, sTextBuff As String
        'index of the fear texts location in sText
        Dim iFearPos As Integer

        sFear = sText

        'Find the location of the keyword afraid
        iFearPos = sFear.ToLower().IndexOf("afraid")

        'Remove all the text preceeding that location.
        'The +7 makes the removal also remove the word afraid and the trailing space
        sFear = sFear.Remove(0, iFearPos + 7)

        'Next questiong that incorperated the fear we have just extracted
        Console.WriteLine("Have you always been afraid " & sFear & "?")
        'Also logged
        strTextFile.WriteLine("EL:Have you always been afraid " & sFear & "?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        'ToLower() is used here so that it picks up on yes regardless of capitilisation
        If (sTextBuff.ToLower() = "yes") Then
            Console.WriteLine("Can you think why your afraid " & sFear & "?")
            strTextFile.WriteLine("EL:Can you think why your afraid " & sFear & "?")
        Else
            Console.WriteLine("What caused your first experience of your fear " & sFear & "?")
            strTextFile.WriteLine("EL:What caused your first experience of your fear " & sFear & "?")
        End If

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        'Copy the reason for the fear to its variable
        sFearReason = sTextBuff

        'Question using this time the fear and the reason
        Console.WriteLine("Well. If " & sFearReason & " is what makes you afraid " & sFear & ". Then maby you should address " & sFearReason)
        strTextFile.WriteLine("EL:Well. If " & sFearReason & " is what makes you afraid " & sFear & ". Then maby you should address " & sFearReason)

        Console.WriteLine("How old were you when you encountered " & sFearReason & "?")
        strTextFile.WriteLine("EL:How old were you when you encountered " & sFearReason & "?")

        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        Console.WriteLine("Encountering " & sFearReason & " at " & sTextBuff & ". You have to be strong about it and counter your fear of " & sFear)
        strTextFile.WriteLine("EL:Encountering " & sFearReason & " at " & sTextBuff & ". You have to be strong about it and counter your fear of " & sFear)

        Console.WriteLine("Can you deal with " & sFearReason & " yourself?")
        strTextFile.WriteLine("EL:Can you deal with " & sFearReason & " yourself?")

        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        If (sTextBuff.ToLower() = "yes") Then
            Console.WriteLine("If thats your problem and you can solve it then you should be ok. Right?")
            strTextFile.WriteLine("EL:If thats your problem and you can solve it then you should be ok. Right?")
        Else
            Console.WriteLine("Well if you can't handle it yourself look for someone who can. ok?")
            strTextFile.WriteLine("EL:Well if you can't handle it yourself look for someone who can. ok?")
        End If

    End Sub

    Sub AngerQuestions()
        'Anger text and input buffers
        Dim sAngry, sAngryLength, sProblem, sTextBuff As String
        'index of the anger texts location in sText
        Dim iAngryPos As Integer

        sAngry = sText

        'Find the location of the keyword angry
        iAngryPos = sAngry.ToLower().IndexOf("angry")

        'Remove all the text preceeding that location.
        'The +6 makes the removal also remove the word angry and it trailing space
        sAngry = sAngry.Remove(0, iAngryPos + 6)

        'Next questiong that incorperated the anger we have just extracted
        Console.WriteLine("How long have you been angry " & sAngry & "?")
        'Also logged
        strTextFile.WriteLine("EL:How long have you been angry " & sAngry & "?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        sAngryLength = sTextBuff

        Console.WriteLine("Why have you been angry " & sAngry & " for " & sAngryLength & "?")
        strTextFile.WriteLine("EL:Why have you been angry " & sAngry & " for " & sAngryLength & "?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        Console.WriteLine("You are angry " & sAngry & ". But what is the problem ?")
        strTextFile.WriteLine("EL:You are angry " & sAngry & ". But what is the problem ?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        sProblem = sTextBuff

        Console.WriteLine("If " & sProblem & " is whats causing your anger " & sAngry & " then maby you can fix it by taking a look at " & sProblem & "?")
        strTextFile.WriteLine("EL:If " & sProblem & " is whats causing your anger " & sAngry & " then maby you can fix it by taking a look at " & sProblem & "?")

    End Sub

    Sub DepressionQuestions()

        'Depression text and input buffers
        Dim sDepression, sTextBuff As String
        'index of the depression texts location in sText
        Dim iDepressionPos As Integer

        sDepression = sText

        'Find the location of the keyword depressed
        iDepressionPos = sDepression.ToLower().IndexOf("depressed")

        'Remove all the text preceeding that location.
        'The +13 makes the removal also remove the word depressed and the word by plus a trailing space
        sDepression = sDepression.Remove(0, iDepressionPos + 13)

        'Next questiong that incorperated the depression we have just extracted
        Console.WriteLine("Have you always been depressed by " & sDepression & "?")
        'Also logged
        strTextFile.WriteLine("EL:Have you always been depressed by " & sDepression & "?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)


        Console.WriteLine("Right, is " & sDepression & " seriously effecting your life at the moment?")
        strTextFile.WriteLine("EL:Right, is " & sDepression & " seriously effecting your life at the moment?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)


        Console.WriteLine("Have you thought about any ways of getting around " & sDepression & "?")
        strTextFile.WriteLine("EL:Have you thought about any ways of getting around " & sDepression & "?")

        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        Console.WriteLine("Do you think talking to someone would help you with " & sDepression & " and help you solve your problem?")
        strTextFile.WriteLine("EL:Do you think talking to someone would help you with " & sDepression & " and help you solve your problem?")


        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        Console.WriteLine("Try staying positive and not let " & sDepression & " get you down and turn to those who care for you")
        strTextFile.WriteLine("EL:Try staying positive and not let " & sDepression & " get you down and turn to those who care for you")
    End Sub

    Sub DoubtfulQuestions()

        'Doubtful text and input buffers
        Dim sDoubtful, sTextBuff As String
        'index of the doubtful texts location in sText
        Dim iDoubtfulPos As Integer

        sDoubtful = sText

        'Find the location of the keyword doubtful
        iDoubtfulPos = sDoubtful.ToLower().IndexOf("doubtful")

        'Remove all the text preceeding that location.
        'The +9 makes the removal also remove the word doubtful and it trailing space
        sDoubtful = sDoubtful.Remove(0, iDoubtfulPos + 9)

        'Next questiong that incorperated the doubt we have just extracted
        Console.WriteLine("Have you always been doubtful " & sDoubtful & "?")
        'Also logged
        strTextFile.WriteLine("EL:Have you always been doubtful " & sDoubtful & "?")

        'Response also logged
        sTextBuff = Console.ReadLine()
        strTextFile.WriteLine("PT:" & sTextBuff)

        'ToLower() is used here so that it picks up on yes regardless of capitilisation
        If (sTextBuff.ToLower() = "yes") Then
            Console.WriteLine("What part " & sDoubtful & " is causing a problem for you at the moment?")
            strTextFile.WriteLine("EL:What part " & sDoubtful & " is causing a problem for you at the moment?")
        Else
            Console.WriteLine("For how long have you known " & sDoubtful & " being a pain in the backside?")
            strTextFile.WriteLine("EL:For how long have you known " & sDoubtful & " being a pain in the backside?")
        End If

    End Sub
End Module
